package cubelabs.nexus.dao;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import cubelabs.nexus.entity.Category;
import cubelabs.nexus.entity.Course;

@Repository("courseDAO")
public class CourseDAO extends BaseDAO<Course, Long>{

	public List<Course> findAllCoursesByCategoryId(Long categoryId) {
		Criteria crit = getSession().createCriteria(getPersistentClass());
		Category category = new Category();
		if(categoryId != null){
			category.setId(categoryId);
			crit.add(Restrictions.eq("category.id", categoryId));
		}
		return crit.list();
	}

}
